export const AdvOTImage = {
    advsListArr: [],
    resUrl: "https://unioncdn.layabox.com/config/iconlist.json",
    data: [],
    resquestTime: 6e4,
    appid: "",
    playIndex: 0,
    lunboTime: 15e3,
    onReadyCallBackFunc: null,
    onChangeCallBackFunc: null,
    isUseAdv: !0,
    clearListId: 0,
    clearLunId: 0,
    http: null,
    init: function () {
        AdvOTImage.isUseAdv && (!AdvOTImage.http && AdvOTImage.isSupperWxJump() && (AdvOTImage.http = new window.XMLHttpRequest), AdvOTImage.onGetAdvsListData(), window.clearInterval(AdvOTImage.clearListId), AdvOTImage.clearListId = window.setInterval(AdvOTImage.onGetAdvsListData, AdvOTImage.resquestTime))
    },
    onGetAdvsListData: function () {
        var e = AdvOTImage.randRange(1e4, 1e6), a = AdvOTImage.resUrl + "?" + e;
        AdvOTImage.http.open("get", a, !0), AdvOTImage.http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"), AdvOTImage.http.responseType = "text", AdvOTImage.http.onerror = function (e) {
            AdvOTImage.onError(e)
        }, AdvOTImage.http.onload = function (e) {
            AdvOTImage.onLoad(e)
        }, AdvOTImage.http.send(null)
    },
    randRange: function (e, a) {
        return Math.floor(Math.random() * (a - e + 1)) + e
    },
    onError: function () {
        console.log("Request failed Status:" + AdvOTImage.http.status + " text:" + AdvOTImage.http.statusText)
    },
    onLoad: function () {
        var e = AdvOTImage.http, a = void 0 !== e.status ? e.status : 200;
        200 === a || 204 === a || 0 === a ? AdvOTImage.complete() : console.log("[" + e.status + "]" + e.statusText + ":" + e.responseURL)
    },
    error: function (e) {
        console.log("error", e)
    },
    complete: function () {
        var e = !0;
        try {
            AdvOTImage.data = AdvOTImage.http.response || AdvOTImage.http.responseText, AdvOTImage.data = JSON.parse(AdvOTImage.data), AdvOTImage.advsListArr = AdvOTImage.data.list, AdvOTImage.appid = AdvOTImage.data.appid, AdvOTImage.updateAdvsInfo()
        } catch (a) {
            e = !1, AdvOTImage.error(a.message)
        }
    },
    updateAdvsInfo: function () {
        AdvOTImage.isUseAdv ? (AdvOTImage.onLunbo(), window.clearInterval(AdvOTImage.clearLunId), AdvOTImage.clearLunId = window.setInterval(AdvOTImage.onLunbo, AdvOTImage.lunboTime)) : window.clearInterval(AdvOTImage.clearLunId)
    },
    onLunbo: function () {
        AdvOTImage.playIndex >= AdvOTImage.advsListArr.length - 1 ? AdvOTImage.playIndex = 0 : AdvOTImage.playIndex += 1, AdvOTImage.revertAdvsData()
    },
    getCurrentAppidObj: function () {
        return AdvOTImage.advsListArr[AdvOTImage.playIndex]
    },
    revertAdvsData: function () {
        AdvOTImage.advsListArr[AdvOTImage.playIndex] && AdvOTImage.onChangeCallBackFunc && AdvOTImage.onChangeCallBackFunc(!0, AdvOTImage.advsListArr[AdvOTImage.playIndex])
    },
    start: function (e) {
        AdvOTImage.isSupperWxJump() ? AdvOTImage.init() : null != e && e(!1)
    },
    change: function (e) {
        AdvOTImage.isSupperWxJump() ? AdvOTImage.onChangeCallBackFunc = e : null != e && e(!1)
    },
    navigateToMiniProgram: function () {
        AdvOTImage.isSupperWxJump() && wx.navigateToMiniProgram({
            appId: AdvOTImage.appid,
            path: "",
            extraData: "",
            envVersion: "release",
            success: function () {
                console.log("跳转成功")
            },
            fail: function () {
                console.log("跳转失败")
            },
            complete: function () {
                console.log("跳转接口调用成功"), AdvOTImage.onLunbo()
            }
        })
    },
    isSupperWxJump: function () {
        if (window.navigator.userAgent.indexOf("MiniGame") < 0) return !1;
        var e = "function" == typeof wx.navigateToMiniProgram;
        return e
    },
    stop: function () {
        AdvOTImage.isUseAdv = !1, window.clearInterval(AdvOTImage.clearLunId), window.clearInterval(AdvOTImage.clearListId), AdvOTImage.http && (AdvOTImage.http.onerror = AdvOTImage.http.onabort = AdvOTImage.http.onprogress = AdvOTImage.http.onload = null, AdvOTImage.http = null),
            this.advsListArr = [], this.data = []
    },
    restart: function () {
        AdvOTImage.isUseAdv = !0, AdvOTImage.init()
    }
};
window.AdvOTImage = AdvOTImage;